// 输入字符串, quack 为大雁的叫声, 大雁一直叫, 本质是求在一个片段中, quack 有多少次重复
const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let initArr = [];
rl.on("line", (line)=>{
    if(initArr.length === 0) {
        initArr = line.trim().split("")
        console.log(getResult(initArr))
        // clear
        initArr.length = 0
    }
})

function getResult(initArr) {
    let res = [] // 收集完整叫声角标范围
    let q = []
    let u = 0
    let a = 0
    let c = 0
    let k = 0

    // 汇总区间
    for (const i in initArr) {
        let char = initArr[i]
        switch (char) {
            case "q":
                q.push(i)
                break;
            case "u":
                if(u+1 <= a.length){
                    u++
                }
                break;
            case "a":
                if(a+1 <= u.length){
                    a++
                }
                break;
            case "c":
                if(c+1 <= a.length){
                    c++
                }
                break;
            case "k":
                if(c >= 1) {
                    res.push([q.shift(), i])
                    u--;
                    a--;
                    c--;
                }
                break;
        }
    }

    // 计数
    if(res.length === 0) return -1;

    let result = 0;
    for (let i = 0; i < res.length; i++) {
        let count = 1;
        const [a, b] = res[i]
        for (let j = i + 1; j < res.length; j++) {
            const [c, d] = res[j]
            if(b > c) count++;
        }
        result = Math.max(result, count)
    }
    return result
}